package com.zbf.moredb.service;

import com.zbf.moredb.dao1.TestDao1Mapper1;
import com.zbf.moredb.dao1.TestDao1Mapper2;
import com.zbf.moredb.dao2.TestDao2Mapper1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/3/24  14:13
 * 描述:
 */
@Component
public class TestService {

    /**
     * 作者: LCG
     * 日期: 2021/3/24  14:14
     * 描述: 数据源 manger2  支持全注解开发
     * @Param 
     * @Return 
     */
    @Autowired
    private TestDao1Mapper1 testDao1Mapper1;

    /**
     * 作者: LCG
     * 日期: 2021/3/24  14:14
     * 描述: 数据源 manger2  支持mapper xml开发
     * @Param
     * @Return
     */
    @Autowired
    private TestDao1Mapper2 testDao1Mapper2;

    /**
     * 作者: LCG
     * 日期: 2021/3/24  14:15
     * 描述:  数据源 manger6  支持注解开发
     * @Param 
     * @Return 
     */
    @Autowired
    private TestDao2Mapper1 testDao2Mapper1;


    @Transactional(rollbackFor = Exception.class)
    public void test101(){

        Map<String,Object> map=new HashMap<>();
        map.put("quantity",10);
        map.put("id",3);
        int i = testDao1Mapper1.update1St1(map);

        if(i==1){
            throw new RuntimeException("======error  please  help======");
        }

    }

    public void test102(){

        Map<String,Object> map=new HashMap<>();
        map.put("quantity",10);
        map.put("id",3);
        int i = testDao1Mapper2.update1Order(map);

    }

    @Transactional(rollbackFor = Exception.class,transactionManager = "transactionManager2")
    public void test201(){

        Map<String,Object> map=new HashMap<>();
        map.put("quantity",10);
        map.put("id",3);
        int i = testDao2Mapper1.update2Stock(map);

        if(i==1){
            throw new RuntimeException("==manger6====error  please  help======");
        }
    }



    @Transactional(rollbackFor = Exception.class,transactionManager = "transactionManager2")
    public void test201101(){

        Map<String,Object> map=new HashMap<>();
        map.put("quantity",10);
        map.put("id",3);
        int i1 = testDao1Mapper1.update1St1(map);
        int i2 = testDao2Mapper1.update2Stock(map);

        if(i1==1){
            throw new RuntimeException("==manger6====error  please  help======");
        }


    }

}
